

package com.hazelcast.internal.serialization.impl.defaultserializers;

import com.hazelcast.internal.serialization.impl.SerializationConstants;
import com.hazelcast.internal.util.MapUtil;
import com.hazelcast.nio.ObjectDataInput;

import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;

/**
 * The {@link ConcurrentHashMap} serializer
 * <p>
 * Important Note: The ConcurrentHashMap 'loadfactor' is not serialized.
 */
public class ConcurrentHashMapStreamSerializer<K, V> extends AbstractMapStreamSerializer<ConcurrentHashMap<K, V>> {
    @Override
    public int getTypeId() {
        return SerializationConstants.JAVA_DEFAULT_TYPE_CONCURRENT_HASH_MAP;
    }

    @Override
    public ConcurrentHashMap<K, V> read(ObjectDataInput in) throws IOException {
        int size = in.readInt();

        ConcurrentHashMap<K, V> map = (ConcurrentHashMap<K, V>) MapUtil.createConcurrentHashMap(size);

        return deserializeEntries(in, size, map);
    }
}
